(function(window, document) {
    angular
        .module('app')
        .factory('payPayokFactory', payPayokFactory);

    payPayokFactory.$inject = ['$http', '$q'];

    function payPayokFactory ($http, $q) {
        var service = {};
        var baseUrl = 'http://www.vipbanlv.com/api/';
        var _orderid = ''; // 订单号
        var _payorderid = ''; // 支付流水号
        var _paytype = ''; // 支付方式
        var _sign = ''; // 签名密钥

        service.setOrderid = function(orderid) {
            _orderid = orderid;
        };

        service.setPayorderid = function(payorderid) {
            _payorderid = payorderid;
        };

        service.setPaytype = function(paytype) {
            _paytype = paytype;
        };

        service.setSign = function(sign) {
            _sign = sign;
        };

        // 购买账号
        service.payPayokPromise = function(accountid) {
            var deferred = $q.defer();
            $http({
                method: 'GET',
                url: baseUrl,
                params: {
                    m: 'pay',
                    a: 'payok',
                    orderid: _orderid,
                    payorderid: _payorderid,
                    paytype: _paytype,
                    sign: _sign
                }
            }).success(function(res) {
                deferred.resolve(res);
            }).error(function() {
                deferred.reject('系统维护升级中！');
            });

            return deferred.promise;
        };

        // 返回service 对象
        return service;
    }
})(window, document);
